<?php
//xxx.php?url=[取得する画像URL]&w=[width]&h=[height]&t=[形式(jpg,png,gifのどれか
//imgg.php?g=images/aa.jpg&w=0&h=100
	//require_once( '../system/login.inc.php' );
	//print_r($_GET);
	
	$url      = isset($_GET['url'])?$_GET['url'] :"images/none.jpg" ;
	$newimage = "images/catche/aaa.jpg";
	//$urlsp = split('.', $url);
	
	$t = isset($_GET['t'])?  $_GET['t'] : "jpg" ; 
	$w = isset($_GET['w']) ? $_GET['w'] : 0;
	$h = isset($_GET['h']) ? $_GET['h'] : 0;
	
	/*ほんとはここでGETで受け取った値のValidationとかをする*/
	
	$image = new Imagick();
	if (file_exists($newimage)){
		$image -> readImageBlob(file_get_contents($newimage));
	}else{
		try{
			$image -> readImageBlob(file_get_contents($url));
			$image -> setImageFormat($t);
			$image -> thumbnailImage($w,$h);
			$image -> writeImage($newimage);
		}catch (Exception $e){
			
			$image -> readImageBlob(file_get_contents("images/none.jpg"));
			//$image -> setImageFormat($t);
			$image -> thumbnailImage($w,$h);
		}
	}
	header('Content-type: image/'.$t);
	echo $image;

?>